package mystack;

import java.util.Stack;

class MinStack {
    Stack<Integer> stack =new Stack<>();
    Stack<Integer> minStack =new Stack<>();
    public MinStack() {
    }

    public void push(int val) {
        if(stack.empty()){
            stack.push(val);
            minStack.push(val);
        }else{
            stack.push(val);
            if(val<=minStack.peek()){
                minStack.push(val);
            }
        }
    }

    public void pop() {
        int tmp = stack.pop();
        if(tmp==minStack.peek()){
            minStack.pop();
        }
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return minStack.peek();
    }
}
